package com.yunhe.sms.controller;

import com.yunhe.webmvc.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/10/16 0016.
 */
 @RequestMapping("/logout")
public class LogoutController {
     @RequestMapping
    public String  logout(HttpServletRequest req, HttpServletResponse resp){
        HttpSession session = req.getSession();
        session.removeAttribute("user");
        session.removeAttribute("userName");


        Cookie[] cookies = req.getCookies();
        if(null != cookies){
            for(Cookie c : cookies){
                if(c.getName().equals("userName")){
                    c.setMaxAge(0);
                    resp.addCookie(c);
                }
                if(c.getName().equals("password")){
                    c.setMaxAge(0);
                    resp.addCookie(c);
                }

            }
        }


        return "redirect:/login";
    }
}
